package org.tool
{
	import flash.filesystem.File;
	
	import mx.collections.ArrayCollection;
	
	public class FileUtility
	{
		 
		public function FileUtility()
		{
			
		}
		
		public function createDirectory(base:String, dirName:String):void {			
			 var newFilePath:String = base + File.separator + dirName;
			 var newDirectory:File = File.desktopDirectory.resolvePath(newFilePath);
			 
   			 newDirectory.createDirectory();
   			
		}
		
		public function deleteDirectory(base:String, dirName:String):void {
			var newFilePath:String = base + File.separator + dirName;
			var newDirectory:File = File.desktopDirectory.resolvePath(newFilePath);
			
			newDirectory.deleteDirectory(true);
 		}
		
		public function renameDirectory(base:String, oldName:String, newName:String):void {
			var newFilePath:String = base + File.separator + newName;
			var newDirectory:File = File.desktopDirectory.resolvePath(newFilePath);
			
			var oldFilePath:String = base + File.separator + oldName;
			var oldDirectory:File = File.desktopDirectory.resolvePath(oldFilePath);
			
			oldDirectory.moveTo(newDirectory, true);
		}
		
		public function listDirectory(base:String, dirName:String):ArrayCollection {
			var newFilePath:String = base + File.separator + dirName;
			var newDirectory:File = File.desktopDirectory.resolvePath(newFilePath);
			var data:Object;
		  
		    
		    var array:Array = newDirectory.getDirectoryListing();
		    var dataList:Array = new Array();
		    var dataListProvider:ArrayCollection = new ArrayCollection();
		    for(var i:int=0; i<array.length; i++){
		    
		     //  if (!array[i].isDirectory()){
		    	data = new Object();
		    	data.name = array[i].name;
		    	data.fileType = array[i].type;
		    	 
		    	data.time = array[i].creationDate.toString();
		    	
		    	 dataListProvider.addItem(data);
		    //   }
		    }
			return dataListProvider;
		}
		
		public function listFileInDirectory():Array{
			
			return null;
		}
			
	}
}